
----------------------------------------------------------------
--- Copyright：  迷你玩-海马
--- Description：服务器的固定url配置
--- 提供的API
---		get_ma_gate_url_cross  获得网关地址ip 外网
---     get_ma_gate_url        获得网关地址ip 内网
----------------------------------------------------------------

local require = require
local ngx     = ngx
local ns_env  = require("modules.env.env")


-- 所有网关配置
local url_config_list = {
	[0] = {
		-- 国内正式
		inner = {
			"http://10.135.54.196:8080",
			"http://10.104.212.48:8080",
			"http://10.104.145.12:8080",
			"http://10.20.10.87:8080",
			"http://10.20.10.32:8080",
		},
		out   = {
			"http://123.207.235.22:8080",
			"http://203.195.177.104:8080",
			"http://193.112.23.173:8080",
			"http://1.14.165.67:8080",
			"http://1.14.144.63:8080",
		},
	},

	[1] = {
		-- 国内测试开发
		inner = {
			"http://120.24.64.132:8080",
			"http://120.24.64.132:8087",
		},
		out   = {
			"http://120.24.64.132:8080",
			"http://120.24.64.132:8087",
		},
	},

	[2] = {
		-- 国内先遣
		inner = { "http://211.159.183.137:8080" },
		out   = { "http://211.159.183.137:8080" },
	},


	[10] = {
		-- 海外正式
		inner = {
			"http://47.88.2.143:8087",
			"http://47.254.69.196:8087",
			"http://47.254.39.28:8087",
			"http://198.11.173.33:8087",
		},
		out   = {
			"http://47.88.2.143:8087",
			"http://47.254.69.196:8087",
			"http://47.254.39.28:8087",
			"http://198.11.173.33:8087",
		},
	},

	[11] = {
		-- 海外测试开发
		inner = { "http://8.210.74.80:8087" },
		out   = { "http://8.210.74.80:8087" },
	},

	[12] = {
		-- 海外先遣
		inner = { "http://47.75.147.207:8087" },
		out   = { "http://47.75.147.207:8087" },
	},
}


local FOO = {
	_VERSION = '0.12.1',
	work_id  =  ngx.worker.id(),
	url_config = {},
};


---按环境初始化配置
function FOO.init()
	FOO.url_config = url_config_list[ ns_env.debug ]

	if  FOO.url_config.inner and #FOO.url_config.inner > 1 then
		FOO.url_config.inner.cc = 0
	end

	if  FOO.url_config.out and #FOO.url_config.out > 1 then
		FOO.url_config.out.cc = 0
	end
end



--------------------------------------------网关操作-------------------------
---获得ma_gate的地址: 外网ip (会轮询分压, 可以跨 华为云/腾讯云/阿里云 使用)
function FOO.get_ma_gate_url_cross()
	local net_ = FOO.url_config.out
	if  net_.cc then
		net_.cc = net_.cc + 1
		if  net_.cc > 65535 then
			net_.cc = 1
		end
		return net_[ ( net_.cc % #net_ ) + 1 ]
	else
		return net_[1]
	end
end


------获得ma_gate的地址: 内网ip (会轮询分压)
function FOO.get_ma_gate_url()
	local net_ = FOO.url_config.inner
	if  net_.cc then
		net_.cc = net_.cc + 1
		if  net_.cc > 65535 then
			net_.cc = 1
		end
		return net_[ ( net_.cc % #net_ ) + 1 ]
	else
		return net_[1]
	end
end


FOO.init();
return FOO;
